#include "Set.h"
#include <QPainter>
#include <QDebug>
#include <QIcon>
#include <QCloseEvent>
#include <QMessageBox>
#include <QGridLayout>
#include <QPalette>

Set::Set(QWidget *parent) : QWidget(parent)
{
    this->setWindowTitle("设置");
//    QPixmap p("image/set.jpg");
//    this->setWidth=p.width();
//    this->setHeight=p.height();
    this->resize(setWidth,setHeight);
    this->setMaximumSize(setWidth,setHeight);
    this->setMinimumSize(setWidth,setHeight);

    this->setWindowIcon(QIcon("image/图标.jpg"));




    iniStyle();

    //设置文本框 透明背景
    QPalette pa=sizeText->palette();
    pa.setBrush(QPalette::Base,QBrush(QColor(0,0,0,0)));
    sizeText->setPalette(pa);



    connect(exitButton,&QPushButton::clicked,[=]{
        this->close();
    });
    connect(saveButton,&QPushButton::clicked,[=]{
        saveSet();
    });
    connect(bold,&QCheckBox::toggled,[=]{
        isBold=bold->isChecked();
    });
    connect(italic,&QCheckBox::toggled,[=]{
        isItalic=italic->isChecked();
    });
}

void Set::iniStyle()
{
    colorButton->setFlat(true);
    saveButton->setFlat(true);
    exitButton->setFlat(true);

    transparencySlider->setMinimum(0);
    transparencySlider->setMaximum(255);
    transparencySlider->setSingleStep(1);
    transparencySlider->setTickPosition(QSlider::TicksBelow);
    transparencySlider->resize(150,30);
    qDebug("%d,%d\n",transparencySlider->width(),transparencySlider->height());

}


void Set::saveSet()
{

}



void Set::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.drawPixmap(0,0,setWidth,setHeight,QPixmap("image/set.jpg"));

    sizeLabel->move(45,30);
    sizeText->move(120,30);

    colorButton->move(30,70);

    transparencyLabel->move(45,120);
    transparencySlider->move(120,120);

    bold->move(45,170);
    italic->move(120,170);

    saveButton->move(30,190);
    exitButton->move(120,190);

}

void Set::closeEvent(QCloseEvent *event)
{
    int a=QMessageBox::question(this,"确定退出？","保存了吗？");
    if(16384==a)
    {}
    else
    {
        event->ignore();
    }
}
